/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package com.xiashitech.agent.instrumentation.netty.netty_v4_1.inst;

import com.google.auto.service.AutoService;
import com.xiashitech.agent.rule.usermatch.Register;
import io.opentelemetry.javaagent.extension.instrumentation.HelperResourceBuilder;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static java.util.Arrays.asList;

//@AutoService(InstrumentationModule.class)
public class NettyInstrumentationModule extends InstrumentationModule {
    public NettyInstrumentationModule() {
        super("xs-netty", "xs-netty-4.1");
    }
    @Override
    public void registerHelperResources(HelperResourceBuilder helperResourceBuilder) {
        helperResourceBuilder.registerForAllClassLoaders(
                "META-INF/services/com.alibaba.dubbo.remoting.exchange",
                "xs-classloader-resources/com.alibaba.dubbo.remoting.exchange");
    }
/*  @Override
  public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
    // Class added in 4.1.0 and not in 4.0.56 to avoid resolving this instrumentation completely
    // when using 4.0.
    return hasClassesNamed("io.netty.handler.codec.http.CombinedHttpHeaders");
  }*/

    @Override
    public List<TypeInstrumentation> typeInstrumentations() {
        return asList(
                //new BootstrapInstrumentation(),
                //new ChannelInstrumentation(),
                //new NettyFutureInstrumentation(),
                //new NettyChannelPipelineInstrumentation(),
               // new DubboInstrumentation()
                //new DefaultChannelPipelineInstrumentation()
                //new AbstractChannelHandlerContextInstrumentation()
        );
    }
  @Override
  public List<String> getAdditionalHelperClassNames() {
    List<String> helperClassNames = new ArrayList();
    helperClassNames.addAll(Arrays.asList(
//            "com.xiashitech.agent.instrumentation.netty.netty_common.HttpClientSpanKeyAttributesExtractor",
//            "com.xiashitech.agent.instrumentation.netty.netty_common.NettyConnectionRequest",
//            "com.xiashitech.agent.instrumentation.netty.netty_common.NettyErrorHolder",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientRequestTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientResponseTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.NettyClientSingletons",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.server.HttpServerRequestTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.server.HttpServerResponseTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.server.HttpServerTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.server.NettyServerSingletons",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.server.CustomNettyDecode",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.AttributeKeys",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_common.client.ConnectionCompleteListener",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_common.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",
//            "com.xiashitech.agent.instrumentation.netty.netty_v4_1.client.HttpClientTracingHandler",

           // "com.xiashitech.agent.instrumentation.dubbo.ServerHandler",
            "com.xiashitech.agent.instrumentation.netty.netty_common.Timer"
            ));
    helperClassNames.addAll(Register.registUserMatch());
    return helperClassNames;
  }
}
